<?php if(!IS_AJAX){?>
<include file="Public:header" />
<if condition="getAccessMenu($accessList, 'Intesys', 'Taskform', 'addForm')">
<!---------------------------添加表格面板------------------------------------->
<style>
	.formTemplate{ position:relative; padding:10px; margin:10px 0; }
	.cover{ height:100%; width:100%; position:absolute; cursor: not-allowed; bottom:0; right:0;border: 1px dashed #eee;}
	.cover:hover{ background:rgba(0,0,0,0.01);}
    .panel-rightMenu{ box-shadow:4px 4px 5px rgba(0,0,0,0.2); border:1px solid #ddd; border-radius:2px;position: fixed;width: 250px; z-index:999; color:#333; display:none;}
    .panel-rightMenu li{ padding-left:20px; padding-top:6px; padding-bottom:6px; font-size:12px;}
    .panel-rightMenu li:hover{ background:#eee; cursor:pointer;}
	.panel-fixed{ position:fixed;}
	.box-fixed{ overflow:auto; padding-right:10px;}
	.f-choiceMember { margin-top:5px;}
	.f-addFormBox{ display:none;}
	/*规则表单的样式*/
	.form-square{ border:1px solid #ddd !important;}
	.color-main{ border-color:#65cea7;}
	.btn-add{ font-size:medium;}
	.btn-add span{ color:#666;}
	.panel-form .panel-body{ min-height:500px; position:relative;}
	.panel-form .btn-type{position: absolute;right: 0;top: 3px;box-shadow: 0 1px 4px rgba(0,0,0,0.14); font-size:12px;z-index: 4;}
	.panel-form .btn-add{ margin-bottom:15px; display:block;}
	.panel-form .btn-preview{ right:10px; bottom:10px; position:absolute;}
	.panel-form .btn-submit{ right:90px; bottom:10px; position:absolute;}
	.panel-form input.form-control{ border:none; border-bottom:1px solid #eee; border-radius:0; background:none;-webkit-box-shadow: 0 0 0px 1000px white inset;    -webkit-appearance:none;}
	.panel-form .form-control:focus{ border-color:#65cea7 !important;}
	.panel-form .bottomLine{ position:absolute; bottom:5px; width:50%;}
	.panel-form .single-row{ position:relative;}
	/*规则组*/
	#addForm{ background:#ffffff;}
	.text-big{ margin-right:15px; margin-top:15px;}
	.text-big.btn-danger{color: #666;background-color: #fff;border-color: #ddd;}
	.text-big.btn-danger:hover{color: #fff;background-color: #d2322d;border-color: #ac2925;}
	.text-big.btn-default:hover{ border:1px solid #ddd; background:#65cea7; color:#fff;}
	.text-big:active{ background:#e2e2e2;}
	.sourceInput{ max-width:60px; margin-bottom:5px;}
	.sourcePanel{text-align: center;position: absolute;top: 20px;background: #fafafa;border: 1px solid #ddd;padding: 5px; display:none; z-index:3;}
	.SelectDataListItem{ border-bottom:1px solid #eee;}
	.ruleGroup{border:1px solid #eee;min-height:50px; position:relative; margin-bottom:20px; margin-top:20px; padding:0px;  cursor:pointer; padding-left:10px; background-color:#fff;min-height: 59px;}
	.ruleGroup > *{ margin-top:10px !important; margin-bottom:10px;}
	.ruleGroup .groupInput{width:110px;}
	.ruleGroup .groupIntro{height: 30px; width: 50%;position: absolute; padding:7px; margin:auto; top:0; bottom:0; left:0; right:0; text-align:center; color:#ddd;}
	/*切换选择*/
	.ruleGroup  a{margin-right:20px; display:none; font-weight:normal; line-height:30px; color:#65cea7; width:60px; border-radius:2px; text-align:center; background:#fff; margin-top:3px;}
	.ruleGroup a:hover{ background:#65cea7; color:#fff;}
	.ruleGroup:hover{ border:1px dashed #aaa;}
	/*规则（组）删除按钮*/
	.ruleGroup > .faicon{position: absolute;z-index: 3;right: 3px;top:-7px;font-size: 16px;color: #65cea7; display:none; cursor:pointer;}
	.ruleGroup .fabg{position: absolute;top: 0;z-index: 2;right: 0;border: 16px solid #65cea7;border-left-color: rgba(0,0,0,0.00);border-bottom-color: rgba(0,0,0,0.00); display:none;}
	.ruleGroup>label{ margin-left:0px; position:relative; padding-right:10px; padding-top:5px; padding-left:10px; background-color:inherit;}
	.ruleGroup>label .faicon{ position:absolute; right:3px; top:0px; color:#65cea7; display:none; cursor:pointer;}
	.ruleGroup>label:hover .faicon{ display:block;}
	.ruleGroup>.item:hover{ outline:1px dashed #65cea7; outline-offset:0px;}
	.intePanel{position: absolute;padding: 6px;background: white;white-space: nowrap;left: 0; top:100%;font-size: 12px;z-index: 	1;box-shadow: 0px 1px 4px rgba(0,0,0,0.14); display:none;}
	.ruleGroup>.item:hover .intePanel{ display:block;}
	/*选择状态*/
	.ruleGroup.selected{ border-left:5px solid #65cea7; background:#fafafa;}
	.ruleGroup.selected > .faicon,.ruleGroup.selected .fabg,.ruleGroup.selected a{  display:block}
	.ruleGroup.selected input.form-control{ border-bottom:1px solid #65cea7;}
	
	.aui_main{ vertical-align:top;}
	.f-choiceMember label{ padding:8px 0;}
	.f-choiceMember .f-sele{ position:absolute; top:-10px; left:100%; white-space:nowrap;}
	.ui-sortable-placeholder {border: 4px dotted #eee;visibility: visible !important; background-color:rgba(255,255,255,0.3);}
    .table tbody tr td {vertical-align:middle;}
</style>
<div class="row  f-addFormBox">
    <div class="col-sm-4">
        <div class="panel-fixed affixelement affix">
            <div class="panel">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-8" style="padding-left:8px;padding-right:8px" data-step="7" data-intro="此处选择规则分类" data-position="bottom">
                            <html:dropdownselect class="typeselect" selected="" name="type" style="height:auto; width:auto;" multi="0" action="{:U('Team/tree')}" title="选择规则"  placeholder="点击选择规则"  listloaded="selectlistloaded"/>
                            <div id="reselecttypelayout" style="top:0; display:none; left:0; bottom:0; right:0; position:fixed; z-index:4999; "></div>
                        </div>
                        <div class="col-sm-4" style="padding-left:0px;padding-right:0px;text-align: center;" >
                            <a href="javascript:void(0);" onClick="_openWindow('<?php echo U('add') ?>',650,'新建积分规则','提交',function(){ $('#ajaxlistboxform').submit();return true;});" class="pull-right btn btn-success btn-block"  data-step="9" data-intro="此处创建新的规则" data-position="bottom" style="padding-left: 0;padding-right:0;width:66px;float:none !important;display: inline-block;">新建规则</a>
                        </div>
                        
                    </div>
                    <br/>
                    <form action="<?php echo U('select');?>" method="post" id="selectdatalistform" >
                        <div class="input-group m-bot15 hidden">
                            <input type="text" name="keywords" class="form-control">
                            <span class="input-group-btn">
                            <button type="submit" class="btn btn-default"><i class="fa icon-search" style="font-size:16px"></i></button>
                            </span>
                        </div>
                    </form>
                    <div id="selectdatalist" class="box-fixed" data-step="8" data-intro="点击选择规则" data-position="top"></div>
                    <div style="text-align:center; position:absolute; bottom:25px;" id="selectdatalistpages"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-8">
        <div class="panel panel-form">
            <div class="panel-heading"  data-step="1" data-intro="这里开始创建表格" data-position="bottom">
                <span class="pagetitle">创建表格</span>
                <a href="javascript:void(0);" class="pull-right f-addRule">返回规则主页</a>
            </div>
            <div class="panel-body">
            	<?php if($specialForm||$particularForm){ ?>
                    <div class="row" >
                    	<?php if($specialForm){ ?>
                        <div class="col-sm-4 f-temp "  data-step="12" data-intro="也可以在默认的表格模板的基础上创建出不同用处的表格！" data-position="bottom">
                            <div class="">通用模板</div>
                            <div>
                                <volist name="specialForm" id="vo">
                                    <span data-id="{$vo.id}" class="text-big btn-sm btn btn-default">{$vo.name}</span>
                                </volist>
                            </div>
                        </div>
                        <?php } ?>
                        <?php if($particularForm){ ?>
                        <div class="col-sm-8 f-temp"   data-step="13" data-intro="或者修改系统重要的表格使得更符合公司的管理制度！" data-position="bottom">
                            <div class="">系统表格</div>
                            <div>
                                <volist name="particularForm" id="vo">
                                    <span data-editid="{$vo.id}" class="text-big btn-sm btn btn-danger">{$vo.name}</span>
                                </volist>
                            </div>
                        </div>
                        <?php } ?>
                    </div>
                    <hr class="color-main"/>
                <?php } ?>
                
                <div class="row">
                    <div class="col-sm-4 col-lg-3">
                        <div class=""  data-step="2" data-intro="这里填写表单名称" data-position="bottom">
                            <input datatype="*" form="addForm" placeholder="请输入表单名称"  nullmsg="名称不能为空" errormsg="不支持特殊字符" class="form-control form-square" value="{$form.name}" name="name" type="text" id="name" size="10" >
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-3">
                        <div class=""  data-step="3" data-intro="这里选择表格分类" data-position="bottom">
                            <select form="addForm" class="form-control" datatype="*" nullmsg="请选择！" id="formcategory_id"  name="formcategory_id">
                                <option value="">请选分类</option>
                                <volist name="formcategory" id="vo">
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <a href="javascript:void(0);" onClick="_openWindow('<?php echo U('Formcategory/add');?>',300,'新增分类','提交',null);" class="btn-block"  data-step="4" data-intro="您也可以新建一个表格分类" data-position="bottom">
                            新增分类
                        </a>
                    </div>
                </div>
                <hr/>
                <div class="row" data-step="5" data-intro="选择表格的审核人" data-position="bottom">
						<span class="col-xs-12">选择审核人</span>
                        <div class="icheck icheckbox">
                            <div class="f-choiceMember" >
                                <div class="">
                                	<div class="radio square-red single-row"><label><input checked type="radio" value="0" name="0">上级审核</label></div>
                                </div>
                                <div class="">
                                	<div class="radio square-red single-row ">
                                    	<label><input type="radio" value="1" name="0">其它人审核</label>
                                    	<div class="pull-right hidden f-sele" >
                                            <html:dropdownselect class="memberselect" selected="" typelimit="1" listloaded="approverlistloaded" name="member" style="height:auto; min-width:90px; width:auto;" multi="0" action="{:U('Team/membergroup')}" title="选择员工" placeholder="点击选择人员" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                </div>
                <hr style=" margin-top:10px;" />
                <span>添加规则</span>
                <form id="addForm" class="checkoutform" action="{:U('Taskform/addForm')}" method="post">
                	<!--主要模板区域-->
                    <div class="ruleTemplate">
                        <div class="ruleGroup form-inline icheck"  data-step="6" data-intro="为表格写入第一条规则" data-position="bottom">
                            <input class="groupType" type="hidden" name="groupType[]" value="checkbox"/>
                            <input name="groupName[]" maxlength="10" type="text" value="" class="form-control groupInput" placeholder="请输入组名"/>
                            <label class="groupName hidden" >请输入组名</label><label>：</label>
                            <a href="javascript:void(0);" class="pull-right btn-type tooltips"  data-original-title="点击切换类型" title="点击切换类型" data-placement="top" data-toggle="tooltip" >
                                多选模式
                            </a>
                            <div class="groupIntro">请在左侧选择规则</div>
                            <i class="fa faicon icon-times" title="删除行"></i>
                            <!--<div class="fabg"></div><i class="fa icon-dot-circle-o"></i>-->
                        </div>
                    </div>
                    <!--隐藏的ruleGroup配置-->
                    <div class="ruleGroup form-inline hidden icheck">
                    	<input class="groupType" type="hidden" name="groupType[]" value="checkbox"/>
                    	<input name="groupName[]" maxlength="10" type="text" class="form-control groupInput" placeholder="请输入组名"/>
                        <label class="groupName hidden">请输入组名</label><label>：</label>  
                        <a href="javascript:void(0);" class="pull-right btn-type tooltips"  data-original-title="点击切换类型" title="点击切换类型" data-placement="top" data-toggle="tooltip" >
                        	多选模式
                        </a>
                        <div class="groupIntro">请在左侧选择规则</div>
                    	<i class="fa faicon icon-times" title="删除行"></i>
                        <!--<div class="fabg"></div>-->
                    </div>
                    <input type="hidden" name="ruleTemplate" id="ruleTemplate"/>
                </form>
                <!--表单模板-->
                <div class="formTemplate"></div>
                <!--底部预留-->
                <div>
                	<div class="bottomLine"></div>
                    <a class=" btn-add" href="javascript:void(0);" > <i class="fa icon-plus-square"></i> <span>添加一行</span></a>&nbsp;
                    <!--<button class="btn btn-warning btn-sm btn-preview"  type="submit"  data-step="10" data-intro="创建完毕，此处可以预览表格" data-position="top">预览</button>-->
                    <button class="btn btn-success btn-sm btn-preview"  type="submit" data-step="11" data-intro="点击此处，即可预览并可以生成想要的表格" data-position="top">生成表格</button>
                </div>
            </div>
        </div> 
    </div>
</div>
</if>
<!---------------------------------规则使用主面板-------------------------------->
<div class="row f-addRuleBox">
    <div class="col-sm-12 col-md-12 col-lg-12">
        <div class="directory-info-row" style="margin-top:0;">
            <section class="panel">
                <div class="panel-heading">
                    <span class="pagetitle">规则详情</span>
                </div>
                <div class="panel-body" style="padding:0 15px 10px;">
                    <div class="tab-content">
                        <div class="tab-pane active adv-table" id="home">
                            <div style="margin:10px 0;">
                                <div class="pull-left">
                                    <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_rule', 'add')">
                                        <button class="btn btn-success" type="button" onclick="_openWindow('<?php echo U('add'); ?>', 650, '新建积分规则', '保存', null, '');">新建规则</button>
                                    </if>
                                    <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_ruletype', 'add')">
                                        <button class="btn btn-success" type="button" onclick="_openWindow('<?php echo U('Integral_ruletype/add') ?>',650,'新建积分规则分类','提交',function(){return true;});">新建分类</button>
                                    </if>
                                    <if condition="getAccessMenu($accessList, 'Intesys', 'Taskform', 'addForm')">
                                        <button class="btn btn-success f-addForm" type="button" >新建积分表格</button>
                                    </if>
                                </div>
                                <div class="pull-right">
                                    <div style="width:210px;float: left;">
                                        <form action="<?php echo U('index');?>" id="ajaxlistboxform">
                                            <!--<input type="hidden" name="type_id" value="">-->
                                            <div class="input-group">
                                                <input type="text" name="keywords" class="form-control" placeholder="请输入关键词匹配搜索">
                    <span class="input-group-btn">
                    <button type="button" onClick="$('#ajaxlistboxform').submit();" class="btn btn-default"><i class="fa icon-search" style="font-size:16px"></i></button>
                    </span>
                                            </div>
                                            <div id="integralcategoryvar"></div>
                                        </form>
                                    </div>
                                    <div style="width:160px;float: left;padding-left:15px">
                                        <html:dropdownselect class="ruleselect" selected="" name="rule" style="height:auto; width:auto;" multi="0" action="{:U('Team/tree')}" title="选择规则"  placeholder="点击选择规则"  listloaded="listloaded" />
                                        <div id="reselectrulelayout" style="top:0; display:none; left:0; bottom:0; right:0; position:fixed; z-index:4999;">
                                        </div>
                                    </div>
                                </div>
                                <div class="clearfix"></div>
                            </div>
                            <table class="display table table-bordered table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>名称</th>
                                        <th>分类</th>
                                        <th class="visible-lg">介绍</th>
                                        <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_rule', 'edit')">
                                            <th>操作</th>
                                        </if>
                                    </tr>
                                </thead>
                                <tbody id="ajaxlistbox">
                                    <?php }?>
                                    <!------------------------ 数据主体-------------------------- -->
                                    
                                    <?php if(IS_AJAX){?>
                                    <volist name="list" id="vo">
                                        <tr id="ajaxlistbox-{$vo.id}" class="DataListItem DataListItembg">
                                            <td title="{$vo.name}"><div class="box-elli">
                                                    {$vo.name}
                                                </div></td>
                                            <td title="{$vo.type_name}"><div class="box-elli">
                                                    {$vo.type_name}
                                                </div></td>
                                            <td title="{$vo.remark}" class="visible-lg"><div class="big_td">
                                                    {$vo.remark}
                                                </div></td>
                                            <td class="text-{:$vo['integralnum']>0?'success':'danger'} hidden">{$vo.integralnum}</td>
                                            <td class="hidden">{$vo.integralTypeName}</td>
                                            <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_rule', 'edit')">
                                            <td class="optionBtnBox" style="width:190px">
                                                    <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_rule', 'edit')">
                                                        <!--<a onClick="_openWindow('{:U('edit',['id'=>$vo['id']])}',650,'修改规则','保存',null,'')" data-placement="top" data-toggle="tooltip" class="tooltips" href="javascript:void(0);" data-original-title="修改积分类型">-->
                                                        <!--</a>-->
                                                        <button class="btn btn-success " type="button"  data-id="{$vo.id}" href="javascript:void(0);"  onClick="_openWindow('{:U('edit',['id'=>$vo['id']])}',650,'修改规则','保存',function(){ $('#ajaxlistboxform').submit();return true; },'')" style="color:#fff">修改规则</button>
                                                    </if>
                                                    <if condition="getAccessMenu($accessList, 'Intesys', 'Integral_rule', 'delete')">
                                                        <!--<a class="button deleteBtn tooltips" data-id="{$vo.id}" href="javascript:void(0);" rel="<?php echo U('delete',['id'=>$vo['id']]) ?>" title="删除规则" data-original-title="修改积分类型"  data-placement="top" data-toggle="tooltip">-->
                                                        <!--</a>-->
                                                        <buttton class="btn btn-success deleteBtn" type="button"  data-id="{$vo.id}" href="javascript:void(0);" rel="<?php echo U('delete',['id'=>$vo['id']]) ?>" style="color:#fff">删除规则</buttton>
                                                    </if>
                                            </td>
                                            </if>
                                        </tr>
                                    </volist>
                                    <?php }?>
                                    <!------------------------ 数据主体结束---------------------- -->
                                    <?php if(!IS_AJAX){?>
                                </tbody>
                            </table>
                            <div id="ajaxlistboxpages" style="text-align:center;">
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<style>
.selectlist{margin:0; padding:0;}
.selectlist li{list-style-type:none; margin:0; padding:0;padding:5px; border-bottom:1px solid #eee; margin:0 8px;}
.selectlist li:hover{background:#eee;}
.selectlist li>ul>li:hover{background:#E7E7E7;}	
.selectlist li>ul>li>ul>li:hover{background:#EBEBEB;}	
.panel-rightMenu{ box-shadow:4px 4px 5px rgba(0,0,0,0.2); border:1px solid #ddd; border-radius:2px;position: fixed;width: 250px; z-index:999; color:#333; display:none;}
.panel-rightMenu li{ padding-left:20px; padding-top:6px; padding-bottom:6px; font-size:12px;}
.panel-rightMenu li:hover{ background:#eee; cursor:pointer;}
#integralcategorybox td{padding:5px;}
.limit_h_36{ height:36px; overflow:hidden;}
</style>
<include file="Public:script" />
<script src="__PUBLIC__/Js/highcharts.src.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/zTree_v3/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript" src="/Public/Js/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
<script>
//
//
//有关表格的脚本
//
function listloaded(){
    $('.ruleselect').blur(function(){
        $("#ajaxlistboxform input[name='type_id']").remove();
        if($('.ruleselect.binded .itemspan').children('input:eq(1)').length!=0){
            $('#ajaxlistboxform').append("<input type='hidden' name='type_id' value='"+$('.ruleselect .itemspan').children("input:eq(1)").attr('value')+"'>");
        }
        $('#ajaxlistboxform').submit();
    });
}
//
//选择审核人时插入数据
function approverlistloaded(){
	$('.memberselect .selectitem').click(function(){
		$(this).find('input').eq(0).attr('name','approvername');
		$(this).find('input').eq(1).attr('name','approver');
	});
	$('.memberselect').blur(function(){
		$("#addForm input[name='approver']").remove()
		$("#addForm input[name='approvername']").remove();
		var id=$('.memberselect .itemspan').children("input:eq(1)");
		var name=$('.memberselect .itemspan').children("input:eq(0)");
		id.attr('name','approver');
		name.attr('name','approvername');
		$('#addForm').append("<input type='hidden' name='"+id.attr('name')+"' value='"+id.attr('value')+"'><input type='hidden' name='"+name.attr('name')+"' value='"+name.attr('value')+"'>");
	});
}
function selectlistloaded(){
    $('.typeselect').blur(function(){
        $("#selectdatalistform input[name='type_id']").remove();
        if($('.typeselect.binded .itemspan').children('input:eq(1)').length!=0){
            $('#selectdatalistform').append("<input type='hidden' name='type_id' value='"+$('.typeselect .itemspan').children("input:eq(1)").attr('value')+"'>");
        }
        $('#selectdatalistform').submit();

        $('.square-red input').iCheck({
            checkboxClass: 'icheckbox_square-red',
            radioClass: 'iradio_square-red',
            increaseArea: '20%'
        });
    });
    //当选择规则的时候，将规则组的规则选中显示
    $(".selectlist").click(function(e) {
        $(".ruleGroup.selected").find(".item").each(function(index, element) {
            var self=$(this);
            window.setTimeout(function(){
                $(".SelectDataListItem."+self.attr('data-target')).addClass('selected');
                $('.square-red input').iCheck({
                    checkboxClass: 'icheckbox_square-red',
                    radioClass: 'iradio_square-red',
                    increaseArea: '20%'
                });
            },500);
        });
    });
}
//恢复默认的状态
function ruleRestore(){
	//绑定选择审核人的事件
	$(".f-choiceMember input").change(function(e) {
		if($(this).val()==0){
			$(".memberselect.binded .itemspan a").click();
			$("#addForm input[name='approver']").remove();
			$("#addForm input[name='approvername']").remove();
			$("#addForm").append('<input type="hidden" name="approver" value=""/><input type="hidden" name="approvername" value=""/>');
			$(this).parents('.f-choiceMember').find('.f-sele').addClass('hidden');
		}else{
			$("#addForm input[name='approver']").remove();
			$("#addForm input[name='approvername']").remove();
			$(this).parents('.f-choiceMember').find('.f-sele').removeClass('hidden').find('.memberselect').html("<span>点击选择人员</span>");
		}
	});
	/*$("#addForm .ruleGroup:not(.hidden)").remove();
	$("#addForm .ruleGroup.hidden:not(:last)").remove();
	$("#addForm input[name='id']").remove();*/
	//清除记录显示界面
	$("#ruleTemplate").removeAttr('value');
	$(".ruleTemplate").html('');
	$(".btn-add").click();

<if condition="getAccessMenu($accessList, 'Intesys', 'Taskform', 'addForm')">
	$("#addForm")[0].reset();
    </if>
	$("#addForm input[name='id']").remove();
	$(".f-choiceMember label:first").click();
}
$(function(){
	//表单验证
	$(".checkoutform:eq(0)").Validform({
		ajaxPost:true,
		tiptype:function(){
			return false;	
		},
		beforeCheck:function(obj){
			//检查是否有字段未填写
			if($(".ruleGroup").eq(-2).find(".groupInput").val()==''){
				$.ThinkBox.error('请将内容填写完整！',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
				$(".ruleGroup").eq(-2).find(".groupInput").focus();
				return false;
			}
			//$(".btn-preview").click();
			//序列化字段的名称
			$("#addForm .ruleGroup").removeClass("selected");
			$(obj).find(".ruleTemplate .ruleGroup").each(function(index, element) {
                $(element).find('.checkbox').each(function(i,e){
					$(e).attr('name','groupRule['+index+']['+i+'][0]');
					$(e).siblings('.sourceInput').attr('name','groupRule['+index+']['+i+'][1]');
				});
            });
			//填充模板的内容
			var html='';
			$(".groupInput").each(function(index, element) {
                $(this).attr('value',$(this).val());
            });
			html=$(".ruleTemplate").html();
			$("#ruleTemplate").val(html);
		},
		callback:function(data){
			$.ThinkBox.success('提交成功',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});
			//打开新创建的表格的窗口
			var url='{:U('Taskform/getform',['id'=>'remind'])}'.replace('remind',data.tbody.id);
			_openWindow(url,1000, data.tbody.name, '确定',function(){ $.ThinkBox.success('领取成功！',{'delayClose':200}); },'');
			setTimeout(function(){ 
				introJs('.aui_content').start();
			},500);
			//初始化
			ruleRestore();
		}
	});
	//当点击通用模板时，表单中显示出模板的表单内容
	$(".f-temp .text-big").click(function(e) {
		var _this=$(this);
		var dataId=$(this).attr('data-id')?$(this).attr('data-id'):$(this).attr('data-editid')
		if(dataId==0){return false;}
		$.getJSON('{:U('Taskform/getTemp')}',{'id':dataId},function(data){
			if(data.status){
				$("#addForm input[name='id']").remove();
				$(".iradio_square-red:eq(0)").click();	
				//判断数据类型
				if(_this.attr('data-id')){
					$(".btn-preview").removeClass("btn-danger").addClass("btn-success").text('生成表格');
				}else if(_this.attr('data-editid')){
					if(Number(data.approver)){
						$(".iradio_square-red:eq(1)").click();
						$(".f-sele>div").html('<span class="itemspan">'+data.approvername+'</span>');
					}
					$("#addForm").append('<input type="hidden" name="id" value="'+data.id+'"/>');
					$(".btn-preview").removeClass("btn-success").addClass("btn-danger").text('修改表格');
				}else{
					return false;	
				}
				//填充表单数值
				if(data.ruleTemplate!=''){
					$("#addForm .ruleTemplate").html(data.ruleTemplate);
					$(".ruleTemplate .ruleGroup:eq(0)").click();
				}else{
					$("#addForm .ruleTemplate").html('');
					$(".btn-add").click();
				}
				if(data.template!=''){
					$(".formTemplate").html(data.template).append('<div class="cover"></div>');
				}else{
					$(".formTemplate").html('');
				}
				$("#name").val(data.name);
				$("#formcategory_id").val(data.formcategory_id);
				$(data.tbody).each(function(index, element) {
					$("#addForm .groupInput").eq(index).removeClass('hidden').val(element.name);
				});
				$("#addForm .ruleGroup:not(:last)").removeClass('hidden').find('.groupInput').removeClass('hidden');
				$(".ruleTemplate").sortable();
			}
		});
    });
	//预览窗口
	$(".btn-preview").click(function(e) {
		if($("#addForm .groupInput").val()&&$("#name").val()&&$("#formcategory_id").val()){
			//清除显示的窗口的选择状态和一些提示信息 	
			$(".sourcePanel").hide();
			$("#addForm .ruleGroup").removeClass("selected");
			var html='';
			var content=$("#addForm .ruleGroup").clone();
			content.find(".groupInput").each(function(index, element) {
                $(this).next().text($(this).val()).removeClass("hidden");
				$(this).remove();
            });
			$(content).find("a").remove();
			$(content).find("i").remove();
			content.removeClass('ruleGroup');
			content.find(".groupIntro").remove();
			//弹出预览窗口
			var mydialog=art.dialog({
				okVal:$(this).text(),
				cancelVal: '取消我',
				title: $("#name").val(),
				content: $('<div>').append(content).html(),
				width:800,
				lock:true,
				height:300,
				cancel:true,
				quickClose: true,
				ok:function(){
					$("#addForm").submit();
				}
			});	
			//渲染Icheck方法
			$('.square-red input').iCheck({
				checkboxClass: 'icheckbox_square-red',
				radioClass: 'iradio_square-red',
				increaseArea: '20%'
			});
		}else{
			//判断是哪个未填写
			if(!$("#formcategory_id").val()){ $("#formcategory_id").focus();}
			if(!$("#name").val()){ $("#name").focus();}
			if(!$("#addForm .groupInput").val()){ $("#addForm .groupInput").focus();}
			$.ThinkBox.error('请填写完内容后预览',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
		}
    });
	//当有一点规则组被选择的时候给一个选择的状态
	$("#addForm").on("click",".ruleGroup",function(){
		$(".SelectDataListItem").removeClass("selected");
		if($(this).hasClass("selected")){
			$(".ruleGroup").removeClass("selected");
		}else{
			$(".ruleGroup").removeClass("selected");
			$(this).addClass("selected");
			//给左边的规则加上选择的状态
			$(this).find(".item").each(function(index, element) {
				$(".SelectDataListItem."+$(this).attr('data-target')).addClass('selected');
            });
		}
		
		
	});
	//当点击关闭的时候
	$("#addForm").on("click",".faicon",function(){
		if(confirm('确定删除？')){
			$(this).parent().remove();	//.parents(".ruleGroup")
		}
	});
	//取消表单的点击事件
	$("#addForm").on("click","input",function(e){
		var e=e||window.event;
		if(e.stopPropagation) {   
			e.stopPropagation();  
		} else {  
			e.cancelBubble = true; 
		}
		if(!$(this).parents(".ruleGroup").hasClass('selected')){
			$(".ruleGroup.selected").removeClass("selected");
			$(this).parents(".ruleGroup").click();
		}
	});
	//点击切换单/多选
	$("#addForm").on("click",".btn-type",function(e){
		var e=e||window.event;
		if(e.stopPropagation) {   
			e.stopPropagation();  
		} else {  
			e.cancelBubble = true; 
		} 
		var obj=$(this).parents(".ruleGroup");
		if(obj.find(".groupType").val()=='radio'){
			obj.find("input[name='1']").attr('type','checkbox');
			obj.find('.groupType').val('checkbox');
			obj.find('.radio div').attr('class','icheckbox_square-red');
			obj.find('.radio').removeClass('radio').addClass('checkbox');
			obj.find(".btn-type").html('多选模式');
		}else {
			obj.find("input[name='1']").attr('type','radio');
			obj.find('.groupType').val('radio');
			obj.find('.checkbox div').attr('class','iradio_square-red');
			obj.find('.checkbox').removeClass('checkbox').addClass('radio');
			obj.find(".btn-type").html('单选模式');
		}
	});
	//当点击添加行的时候
	$(".btn-add").click(function(){
		if($(".ruleGroup").eq(-2).find(".groupInput").val()!=''||$(".ruleGroup").length<2){
			$(".ruleGroup.hidden").clone().removeClass("hidden").appendTo($(".ruleTemplate"));
			$(".ruleGroup").eq(-2).click();
			$(".ruleTemplate").sortable();
		}else{
			$(".ruleGroup").eq(-2).find(".groupInput").focus();
			$.ThinkBox.error('请填写完内容后添加 ',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
		}
	});
	
	//当规则被点击的时候，在区域中创建选项
	$("#selectdatalist").on("click",".SelectDataListItem ",function(){
		var obj=$(this).find(".sourceList");
		if($("#addForm .ruleGroup.selected").find("."+obj.attr("data-source")).length){
			$("#addForm .ruleGroup.selected").find("."+obj.attr("data-source")).remove();
		}else{
			$("#addForm .ruleGroup.selected").append(obj.html()).find(".groupIntro").remove();
		}
		$(this).toggleClass("selected");
		if($("#addForm .ruleGroup.selected").length==0){
			$.ThinkBox.error('请选择行',{'delayClose':1000,modal:false, 'close': '关闭',x:0,y:0,center:false,locate:['left','top'], show:['',0]});	
			$(this).removeClass("selected");	
		}
	});
	//计算panel-fixed的窗口高度,内容高度，滚动条
	(function(){
		var obj=$(".panel-fixed");
		var height=$(window).height()-110;
		obj.find(".panel-body").height(height);
		obj.find(".box-fixed").height(height-140).niceScroll({styler:"fb",cursorcolor:"#65cea7", cursorwidth: '3', cursorborderradius: '0px', background: '#424f63', spacebarenabled:false, cursorborder: '0'});
	})();
	//初始化界面
	ruleRestore();
});
//
//
//有关规则的脚本
//
//
$(function () {
	//如果新建积分表格
	$(".f-addForm").click(function(e) {
		$(".f-addFormBox").slideDown(500);
		$(".f-addRuleBox").slideUp(500);
		$(window).trigger('resize');
    });
	//如果返回查看规则
	$(".f-addRule").click(function(e) {
		$(".f-addFormBox").slideUp(500);
		$(".f-addRuleBox").slideDown(500);
    });
	//规则固定图表
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {text: '积分管理系统积分规则'},
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false
                },
                showInLegend: true
            }
        },
        series: [{type: 'pie',name: '规则分数占比',data: [['工作分',66],['能力分',10],['综合表现',24]]}]
    });
});
	//获取规则数据，同时渲染工具提示
    $('#ajaxlistbox').ajaxlist({success:function(){$('.tooltips').tooltip();},loading:'<tr><td colspan="4"><div class="lockwindowlayout" id="lockwindowlayout" style="overflow:hidden; padding:10px 0;"><div class="loader-inner line-scale" style="text-align:center;"><div></div><div></div><div></div><div></div><div></div></div><style>.lockwindowlayout .line-scale{height:20px;}.lockwindowlayout .line-scale div{background:#5ec8ff; height:20px;}</style></div></td></tr>',nodata:'<tr><td colspan="4" style="text-align: center;">暂无数据</td></tr>'});
	$("#selectdatalist").ajaxlist();
	


	$(window).trigger("load");
</script>
</body></html><?php }?>